var gulp = require('gulp');
var spritesmith = require('gulp.spritesmith');
var csso = require('gulp-csso');
var imagemin = require('gulp-imagemin');
var merge = require('merge-stream');
var buffer = require('vinyl-buffer');
var watch = require('gulp-watch');

gulp.task('sprite', function () {
  var spriteData = gulp.src('static/sprites/dd/*.png').pipe(spritesmith({
    imgName: 'input_sprite.png',
    cssName: 'input_sprite.css'
  }));
  var cssStream = spriteData.css
    .pipe(csso())
    .pipe(gulp.dest('dist/static/sprites/input'));
  return spriteData.pipe(gulp.dest('dist/sprite_s'));

  var imgStream = spriteData.img
  // DEV: We must buffer our stream into a Buffer for `imagemin`
    .pipe(buffer())
    .pipe(imagemin())
    .pipe(gulp.dest('dist/sprite_s'));
});


gulp.task('watch', function () {
  // Endless stream mode
  gulp.watch('static/sprites/dd/*.png',['sprite']);
});
